package Maps 
{
	import com.greensock.TweenLite;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author Serg de Adelantado
	 */
	public class MapRegion extends Sprite 
	{	
		private var FPoints:Vector.<Point>;
		private var FID:int;
		private var FStatus:int;
		private var FPrice:String;
		private var FPriceCredit:String;
		private var FSize:String;
		
		public function MapRegion() 
		{
			FPoints = new Vector.<Point>;
			useHandCursor = buttonMode = true;
			addEventListener(MouseEvent.MOUSE_OVER, OnMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, OnMouseOut);
			alpha = 0.5;
		}
		
		private function OnMouseOver(e:MouseEvent):void 
		{
			TweenLite.to(this, 0.5, {alpha:1});
		}
		
		private function OnMouseOut(e:MouseEvent):void 
		{
			TweenLite.to(this, 0.5, { alpha:0.5 } );			
		}
		
		public function set Points(APoints:String):void 
		{
			var vPoints:Array = APoints.split(',');
			var vColor:uint = 0;
			for (var i in vPoints)
			{
				var vPoint:Array = String(vPoints[i]).split(':');
				FPoints.push(new Point(int(vPoint[0]), int(vPoint[1])));
			}
			switch (FStatus) 
			{
				case 1:					
					vColor = 0xC04548;
				break;
				case 2:					
					vColor = 0xC19637;
				break;
				case 3:					
					vColor = 0x749E76;
				break;
				default:
					vColor = 0;
				break;
			}
			graphics.beginFill(vColor, 0.5);
			graphics.lineStyle(1, 0, 0);
			graphics.moveTo(FPoints[0].x, FPoints[0].y)
			for (var j:int = 1; j < FPoints.length; j++)
			{				
				graphics.lineTo(FPoints[j].x, FPoints[j].y);
			}
			graphics.endFill();
		}
		
		public function get ID():int 
		{
			return FID;
		}
		
		public function set ID(value:int):void 
		{
			FID = value;
		}
		
		public function get Status():int
		{ 
			return FStatus; 
		}
		
		public function set Status(AStatus:int):void 
		{
			FStatus = AStatus;
		}
		
		public function get Price():String 
		{
			return FPrice;
		}
		
		public function set Price(value:String):void 
		{
			FPrice = value;
		}
		
		public function get PriceCredit():String 
		{
			return FPriceCredit;
		}
		
		public function set PriceCredit(value:String):void 
		{
			FPriceCredit = value;
		}
		
		public function get Size():String 
		{
			return FSize;
		}
		
		public function set Size(value:String):void 
		{
			FSize = value;
		}
	}
}